<template>
	<section>
		<!--工具条-->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
			<el-form :inline="true" :model="filters">
				<el-form-item>
					<template>
					  <el-select  @change="selectedShop" v-model="selectedShopId" placeholder="请选择要查询的店铺">
						<el-option
							v-for="(item,i) in shops"
							:key="i" :label="item.shopName" :value="item.shopId" >
							  {{item.shopName}}
						 </el-option>
					  </el-select>
					</template>
				</el-form-item>
			</el-form>
		</el-col>

		<!--列表-->
		<el-table v-if="evaluateList!=''" :data="evaluateList" highlight-current-row v-loading="listLoading" style="width: 100%;">
			<el-table-column type="selection" width="55">
			</el-table-column>
			<el-table-column label="序号" type="index" width="60">
			</el-table-column>
			<el-table-column
					prop="evaluationScore"
					label="评分"
					width="180">
			</el-table-column>
			<el-table-column
					prop="evaluationContent"
					label="评价内容"
					width="180">
			</el-table-column>
			<el-table-column
					prop="replyEntity.replyContent"
					label="回评内容"
					width="180">
			</el-table-column>
			<el-table-column label="操作" width="150">
				<template scope="scope">
					<el-button size="small" @click="handleCheck(scope.$index, scope.row)">查看订单商品</el-button>
					<el-button disabled v-if="scope.row.replyId!=null" size="small">已回评</el-button>
					<el-button v-else size="small" @click.native="handleEdit(scope.$index, scope.row)">回评</el-button>
<!--					<el-button type="danger" size="small" @click="handleDel(scope.$index, scope.row)">完成</el-button>-->
				</template>
			</el-table-column>
		</el-table>

		<!--工具条-->
		<el-col :span="24" class="toolbar">
<!--			<el-button type="danger" @click="batchRemove" :disabled="this.sels.length===0">批量删除</el-button>-->
			<el-pagination layout="prev, pager, next" @current-change="handleCurrentChange" :page-size="5" :total="total" style="float:right;">
			</el-pagination>
		</el-col>

		<!--订单明细界面-->
		<el-dialog title="订单商品" :visible.sync="checkFormVisible" :close-on-click-modal="false">
			<el-table
					:data="checkForm"
					stripe
					style="width: 100%">
				<el-table-column label="序号" type="index" width="180">
				</el-table-column>
				<el-table-column
						prop="goodsName"
						label="商品名"
						width="180">
				</el-table-column>
				<el-table-column
						prop="goodsPrice"
						label="商品价格"
						width="180">
				</el-table-column>
			</el-table>
			<div slot="footer" class="dialog-footer">
				<el-button @click.native="checkFormVisible = false">返回</el-button>
			</div>
		</el-dialog>

		<!--编辑界面-->
		<el-dialog title="回评" :visible.sync="editFormVisible" :close-on-click-modal="false">
			<el-form :model="editForm" label-width="80px" :rules="editFormRules" ref="editForm">
				<el-form-item label="回评内容" prop="replyContent">
					<el-input v-model="editForm.replyContent" auto-complete="off"></el-input>
				</el-form-item>

			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click.native="editFormVisible = false">取消</el-button>
				<el-button type="primary" @click.native="editSubmit" :loading="editLoading">提交</el-button>
			</div>
		</el-dialog>


	</section>
</template>

<script>
	import { getUserListPage, removeUser, batchRemoveUser, editUser, addUser } from '../../api/api';

	export default {
		data() {
			return {
				filters: {
					name: ''
				},
				page: [],
				goods:[],
				evaluateList:'',
				total: 0,
				pageNum: 1,
				file:'',
				shops:'',
				selectedOrderId:'',
				selectedEvaluationId:'',
				selectedShopId:'',
				listLoading: false,
				editFormVisible: false,//编辑界面是否显示
				checkFormVisible: false,//明细界面是否显示
				editLoading: false,
				editFormRules: {
					name: [
						{ required: true, message: '请输入姓名', trigger: 'blur' }
					]
				},
				//编辑界面数据
				editForm: {
					replyContent:'',
				},
				//订单明细界面数据
				checkForm:{

				}

			}
		},
		methods: {
			overFormatter(row,col){
				return row.isOver === 1?'已完成':'未完成'
			},
			payFormatter(row,col){
				return row.isPay === 1?'已付款':'未付款'
			},
			handleCheck(index, row){
				this.checkFormVisible = true
				this.checkForm = row.orderDetailEntityList
				// console.log(row.orderDetailEntityList)
			},
			selectedShop(data){
				this.selectedShopId=data
				this.getEvaluate()
			},
			getEvaluate(){
				this.$axios({
					method:'get',
					url:'/order/getEvaluate',
					params:{
						shopId:this.selectedShopId
					}
				}).then(r=>{
					this.evaluateList = r.data.result
				}).catch(err=>{
					this.$error()
				})
			},
			handleCurrentChange(val) {
				this.pageNum = val;
				// this.getGoodsPage();
			},
			getShops(){
				this.$axios({	
					method:'get',
					params:{
						merchantId:this.$store.state.user.merchantId
					},
					url:'/merchant/getShop'
				}).then(r=>{
					this.shops = r.data.result
				}).catch(err=>{
					this.$error()
				})
			},
			//显示编辑界面
			handleEdit: function (index, row) {
				this.editFormVisible = true;
				this.selectedOrderId = row.orderId
				this.selectedEvaluationId = row.evaluationId
				// this.editForm = Object.assign({}, row);
			},
			//编辑
			editSubmit: function () {
				this.$refs.editForm.validate((valid) => {
					if (valid) {
						this.$confirm('确认提交吗？', '提示', {}).then(() => {
							this.editLoading = true;
							//NProgress.start();
							let para = {...this.editForm,orderId:this.selectedOrderId,evaluationId:this.selectedEvaluationId,shopId:this.selectedShopId}
							this.$axios({
								method:'post',
								data:para,
								url:'/order/publishReply'
							}).then(r=>{
								if(r.data.err_code===0){
									this.$message.success('回评成功')
									this.getEvaluate()
								}else{
									this.$message.error('回评失败')
								}
								this.editFormVisible=false
								this.editLoading=false
							}).catch(err=>{
								this.$error()
								this.editFormVisible=false
								this.editLoading=false
							})
						});
					}
				});
			},
		},
		created() {
			// this.getGoodsPage()
			this.getShops()
		}
	}

</script>

<style scoped>

</style>